/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_ATOMIC_H
#define M_ATOMIC_H

namespace Engine
{
	/**
	*   Atomically write Value to Target.
	*   @return previous value of Target.
	*/
	long AtomicExchange(volatile long * Target, long Value);

	/**
	*   Atomically increment Target.
	*/
	void AtomicIncrement(volatile long * Target);

	/**
	*   Atomically decrement Target.
	*/
	void AtomicDecrement(volatile long * Target);

	/**
	*   Atomically:  if(*ptr == oldVal){*ptr = newVal}.
	*   @return true if new value was assigned to ptr.
	*/
	bool AtomicCompareExchange(volatile long* ptr, long oldVal, long newVal);

	/**
	*   Atomically:  if(ptr[0] == old1 && ptr[1] == old2){ptr[0] = new1; ptr[1] = new2;}.
	*   @return true if new value was assigned to ptr.
	*/
	bool AtomicCompareExchange64(volatile long* ptr, long old1, unsigned int old2, long new1, unsigned int new2);
}
#endif

